home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / graphics / 3dview12.zip / VESAPROC.CPP < prev    next >
Text File  |  1996-05-28  |  14KB  |  399 lines

  1. void VESA_Pix8BC ( long X , long Y , unsigned long C , unsigned short Selector ) {
  2.     if ( X < VESA_MinX ) return;
  3.     if ( X > VESA_MaxX ) return;
  4.     if ( Y < VESA_MinY ) return;
  5.     if ( Y > VESA_MaxY ) return;
  6.     *(char far*)( Selector :> (char*)( Y * VESA_BpL + X ) ) = char( C );
  7. };
  8.  
  9. void VESA_FilledTriangleTex8BC( long x1, long y1, long x2, long y2, long x3, long y3,
  10.                                 long tx1, long ty1, long tx2, long ty2,
  11.                                 long tx3, long ty3, DWORD MUL, WORD S ) {
  12.     long m,i;
  13.     long x12,x13,x23,m12,m13,m23;
  14.     long tx12,tx13,tx23,mtx12,mtx13,mtx23;
  15.     long ty12,ty13,ty23,mty12,mty13,mty23;
  16.     if ( y1 >= y2 ) {
  17.         m = y1; y1 = y2; y2 = m;
  18.         m = x1; x1 = x2; x2 = m;
  19.         m = tx1; tx1 = tx2; tx2 = m; 
  20.         m = ty1; ty1 = ty2; ty2 = m; };
  21.     if ( y2 >= y3 ) {
  22.         m = y2; y2 = y3; y3 = m;
  23.         m = x2; x2 = x3; x3 = m;
  24.         m = tx2; tx2 = tx3; tx3 = m; 
  25.         m = ty2; ty2 = ty3; ty3 = m; };
  26.     if ( y1 >= y2 ) {
  27.         m = y1; y1 = y2; y2 = m;
  28.         m = x1; x1 = x2; x2 = m;
  29.         m = tx1; tx1 = tx2; tx2 = m; 
  30.         m = ty1; ty1 = ty2; ty2 = m; };
  31.     x12 = x1 << 16;
  32.     x13 = x1 << 16;
  33.     x23 = x2 << 16;
  34.     tx12 = tx1 << 16;
  35.     tx13 = tx1 << 16;
  36.     tx23 = tx2 << 16;
  37.     ty12 = ty1 << 16;
  38.     ty13 = ty1 << 16;
  39.     ty23 = ty2 << 16;
  40.     if ( y2 != y1 ) { m12   = ( (  x2 -  x1 ) << 16 ) / ( y2 - y1 );
  41.                       mtx12 = ( ( tx2 - tx1 ) << 16 ) / ( y2 - y1 ); 
  42.                       mty12 = ( ( ty2 - ty1 ) << 16 ) / ( y2 - y1 ); };
  43.     if ( y3 != y1 ) { m13  = ( ( x3 - x1 ) << 16 ) / ( y3 - y1 ); 
  44.                       mtx13 = ( ( tx3 - tx1 ) << 16 ) / ( y3 - y1 ); 
  45.                       mty13 = ( ( ty3 - ty1 ) << 16 ) / ( y3 - y1 ); };
  46.     if ( y3 != y2 ) { m23  = ( ( x3 - x2 ) << 16 ) / ( y3 - y2 ); 
  47.                       mtx23 = ( ( tx3 - tx2 ) << 16 ) / ( y3 - y2 ); 
  48.                       mty23 = ( ( ty3 - ty2 ) << 16 ) / ( y3 - y2 ); };
  49.     for ( i = y1; i < y2; i++ ) {
  50.         VESA_HLineTex8B( x12 >> 16, x13 >> 16, i, tx12, ty12, tx13, ty13,
  51.                          MUL, S );
  52.         x12 += m12;
  53.         x13 += m13;
  54.         tx12 += mtx12;
  55.         ty12 += mty12;
  56.         tx13 += mtx13;
  57.         ty13 += mty13; };
  58.     for ( ; i <= y3; i++ ) {
  59.         VESA_HLineTex8B( x13 >> 16, x23 >> 16, i, tx13, ty13, tx23, ty23,
  60.                          MUL, S );
  61.         x13 += m13;
  62.         x23 += m23;
  63.         tx13 += mtx13;
  64.         ty13 += mty13;
  65.         tx23 += mtx23;
  66.         ty23 += mty23; };
  67. };
  68.  
  69. void VESA_FilledTriangleTexZ8BC( long x1, long y1, long x2, long y2, long x3, long y3,
  70.                                  long tx1, long ty1, long tx2, long ty2,
  71.                                  long tx3, long ty3, long z1, long z2, long z3,
  72.                                  DWORD MUL, WORD ZSEL, WORD S ) {
  73.     long m,i;
  74.     long x12,x13,x23,m12,m13,m23;
  75.     long tx12,tx13,tx23,mtx12,mtx13,mtx23;
  76.     long ty12,ty13,ty23,mty12,mty13,mty23;
  77.     long z12,z13,z23,mz12,mz13,mz23;
  78.     if ( y1 >= y2 ) {
  79.         m = y1; y1 = y2; y2 = m;
  80.         m = x1; x1 = x2; x2 = m;
  81.         m = z1; z1 = z2; z2 = m;
  82.         m = tx1; tx1 = tx2; tx2 = m; 
  83.         m = ty1; ty1 = ty2; ty2 = m; };
  84.     if ( y2 >= y3 ) {
  85.         m = y2; y2 = y3; y3 = m;
  86.         m = x2; x2 = x3; x3 = m;
  87.         m = z2; z2 = z3; z3 = m;
  88.         m = tx2; tx2 = tx3; tx3 = m; 
  89.         m = ty2; ty2 = ty3; ty3 = m; };
  90.     if ( y1 >= y2 ) {
  91.         m = y1; y1 = y2; y2 = m;
  92.         m = x1; x1 = x2; x2 = m;
  93.         m = z1; z1 = z2; z2 = m;
  94.         m = tx1; tx1 = tx2; tx2 = m; 
  95.         m = ty1; ty1 = ty2; ty2 = m; };
  96.     x12 = x1 << 16;
  97.     x13 = x1 << 16;
  98.     x23 = x2 << 16;
  99.     z12 = z1;
  100.     z13 = z1;
  101.     z23 = z2;
  102.     tx12 = tx1 << 16;
  103.     tx13 = tx1 << 16;
  104.     tx23 = tx2 << 16;
  105.     ty12 = ty1 << 16;
  106.     ty13 = ty1 << 16;
  107.     ty23 = ty2 << 16;
  108.     if ( y2 != y1 ) { m12   = ( ( x2 - x1 ) << 16 ) / ( y2 - y1 );
  109.                       mz12   = ( ( z2 - z1 ) ) / ( y2 - y1 );
  110.                       mtx12 = ( ( tx2 - tx1 ) << 16 ) / ( y2 - y1 ); 
  111.                       mty12 = ( ( ty2 - ty1 ) << 16 ) / ( y2 - y1 ); };
  112.     if ( y3 != y1 ) { m13  = ( ( x3 - x1 ) << 16 ) / ( y3 - y1 ); 
  113.                       mz13   = ( ( z3 - z1 ) ) / ( y3 - y1 );
  114.                       mtx13 = ( ( tx3 - tx1 ) << 16 ) / ( y3 - y1 ); 
  115.                       mty13 = ( ( ty3 - ty1 ) << 16 ) / ( y3 - y1 ); };
  116.     if ( y3 != y2 ) { m23  = ( ( x3 - x2 ) << 16 ) / ( y3 - y2 ); 
  117.                       mz23   = ( ( z3 - z2 ) ) / ( y3 - y2 );
  118.                       mtx23 = ( ( tx3 - tx2 ) << 16 ) / ( y3 - y2 ); 
  119.                       mty23 = ( ( ty3 - ty2 ) << 16 ) / ( y3 - y2 ); };
  120.     for ( i = y1; i < y2; i++ ) {
  121.         VESA_HLineTexZ8B( x12 >> 16, x13 >> 16, i, tx12, ty12, tx13, ty13, z12, z13,
  122.                          MUL, ZSEL, S );
  123.         x12 += m12;
  124.         x13 += m13;
  125.         z12 += mz12;
  126.         z13 += mz13;
  127.         tx12 += mtx12;
  128.         ty12 += mty12;
  129.         tx13 += mtx13;
  130.         ty13 += mty13; };
  131.     for ( ; i <= y3; i++ ) {
  132.         VESA_HLineTexZ8B( x13 >> 16, x23 >> 16, i, tx13, ty13, tx23, ty23, z13, z23,
  133.                          MUL, ZSEL, S );
  134.         x13 += m13;
  135.         x23 += m23;
  136.         z13 += mz13;
  137.         z23 += mz23;
  138.         tx13 += mtx13;
  139.         ty13 += mty13;
  140.         tx23 += mtx23;
  141.         ty23 += mty23; };
  142. };
  143.  
  144. void VESA_FilledTriangleZBuf8BC( long x1, long y1, long x2, long y2, long x3, long y3,
  145.                                   long z1, long z2, long z3,
  146.                                   DWORD C, WORD ZSEL, WORD S ) {
  147.     long m,i;
  148.     long x12,x13,x23,m12,m13,m23;
  149.     long z12,z13,z23;
  150.     long mz12,mz13,mz23;
  151.     if ( y1 >= y2 ) {
  152.         m = y1; y1 = y2; y2 = m;
  153.         m = x1; x1 = x2; x2 = m;
  154.         m = z1; z1 = z2; z2 = m; };
  155.     if ( y2 >= y3 ) {
  156.         m = y2; y2 = y3; y3 = m;
  157.         m = x2; x2 = x3; x3 = m;
  158.         m = z2; z2 = z3; z3 = m; };
  159.     if ( y1 >= y2 ) {
  160.         m = y1; y1 = y2; y2 = m;
  161.         m = x1; x1 = x2; x2 = m;
  162.         m = z1; z1 = z2; z2 = m; };
  163.     x12 = x1 << 16;
  164.     x13 = x1 << 16;
  165.     x23 = x2 << 16;
  166.     z12 = z1;
  167.     z13 = z1;
  168.     z23 = z2;
  169.     if ( y2 != y1 ) { m12  = ( ( x2 - x1 ) << 16 ) / ( y2 - y1 );
  170.                       mz12 = ( z2 - z1 ) / ( y2 - y1 ); };
  171.     if ( y3 != y1 ) { m13  = ( ( x3 - x1 ) << 16 ) / ( y3 - y1 ); 
  172.                       mz13 = ( z3 - z1 ) / ( y3 - y1 ); };
  173.     if ( y3 != y2 ) { m23  = ( ( x3 - x2 ) << 16 ) / ( y3 - y2 ); 
  174.                       mz23 = ( z3 - z2 ) / ( y3 - y2 ); };
  175.     for ( i = y1; i < y2; i++ ) {
  176.         VESA_HLineZ8B( x12 >> 16, x13 >> 16, i, z12, z13, C, ZSEL, S );
  177.         x12 += m12;
  178.         x13 += m13;
  179.         z12 += mz12;
  180.         z13 += mz13; };
  181.     for ( ; i <= y3; i++ ) {
  182.         VESA_HLineZ8B( x23 >> 16, x13 >> 16, i, z23, z13, C, ZSEL, S );
  183.         x13 += m13;
  184.         x23 += m23;
  185.         z13 += mz13;
  186.         z23 += mz23; };
  187. };
  188.  
  189. void VESA_FilledTriangleGZBuf8BC( long x1, long y1, long x2, long y2, long x3, long y3,
  190.                                    long z1, long z2, long z3, long c1, long c2, long c3,
  191.                                    WORD ZSEL, WORD S ) {
  192.     long m,i;
  193.     long x12,x13,x23,m12,m13,m23;
  194.     long z12,z13,z23,mz12,mz13,mz23;
  195.     long c12,c13,c23,mc12,mc13,mc23;
  196.     if ( y1 >= y2 ) {
  197.         m = y1; y1 = y2; y2 = m;
  198.         m = x1; x1 = x2; x2 = m;
  199.         m = c1; c1 = c2; c2 = m;
  200.         m = z1; z1 = z2; z2 = m; };
  201.     if ( y2 >= y3 ) {
  202.         m = y2; y2 = y3; y3 = m;
  203.         m = x2; x2 = x3; x3 = m;
  204.         m = c2; c2 = c3; c3 = m;
  205.         m = z2; z2 = z3; z3 = m; };
  206.     if ( y1 >= y2 ) {
  207.         m = y1; y1 = y2; y2 = m;
  208.         m = x1; x1 = x2; x2 = m;
  209.         m = c1; c1 = c2; c2 = m;
  210.         m = z1; z1 = z2; z2 = m; };
  211.     x12 = x1 << 16;
  212.     x13 = x1 << 16;
  213.     x23 = x2 << 16;
  214.     z12 = z1;
  215.     z13 = z1;
  216.     z23 = z2;
  217.     c12 = c1 << 16;
  218.     c13 = c1 << 16;
  219.     c23 = c2 << 16;
  220.     if ( y2 != y1 ) { m12  = ( ( x2 - x1 ) << 16 ) / ( y2 - y1 );
  221.                       mc12 = ( ( c2 - c1 ) << 16 ) / ( y2 - y1 ); 
  222.                       mz12 = ( z2 - z1 ) / ( y2 - y1 ); };
  223.     if ( y3 != y1 ) { m13  = ( ( x3 - x1 ) << 16 ) / ( y3 - y1 ); 
  224.                       mc13 = ( ( c3 - c1 ) << 16 ) / ( y3 - y1 ); 
  225.                       mz13 = ( z3 - z1 ) / ( y3 - y1 ); };
  226.     if ( y3 != y2 ) { m23  = ( ( x3 - x2 ) << 16 ) / ( y3 - y2 ); 
  227.                       mc23 = ( ( c3 - c2 ) << 16 ) / ( y3 - y2 ); 
  228.                       mz23 = ( z3 - z2 ) / ( y3 - y2 ); };
  229.     for ( i = y1; i < y2; i++ ) {
  230.         VESA_HLineGZ8B( x12 >> 16, x13 >> 16, i, z12, z13, c12, c13, ZSEL, S );
  231.         x12 += m12;
  232.         x13 += m13;
  233.         c12 += mc12;
  234.         c13 += mc13;
  235.         z12 += mz12;
  236.         z13 += mz13; };
  237.     for ( ; i <= y3; i++ ) {
  238.         VESA_HLineGZ8B( x23 >> 16, x13 >> 16, i, z23, z13, c23, c13, ZSEL, S );
  239.         x13 += m13;
  240.         x23 += m23;
  241.         c13 += mc13;
  242.         c23 += mc23;
  243.         z13 += mz13;
  244.         z23 += mz23; };
  245. };
  246.  
  247. void VESA_FilledTriangleG8BC( long x1, long y1, long x2, long y2, long x3, long y3,
  248.                                long c1, long c2, long c3, WORD S ) {
  249.     
  250.     long m,i;
  251.     long x12,x13,x23,m12,m13,m23;
  252.     long c12,c13,c23,mc12,mc13,mc23;
  253.     long dcdx12,dcdx23;
  254.     
  255.     if ( y1 >= y2 ) {
  256.         m = y1; y1 = y2; y2 = m;
  257.         m = x1; x1 = x2; x2 = m;
  258.         m = c1; c1 = c2; c2 = m; }
  259.     if ( y2 >= y3 ) {
  260.         m = y2; y2 = y3; y3 = m;
  261.         m = x2; x2 = x3; x3 = m;
  262.         m = c2; c2 = c3; c3 = m; };
  263.     if ( y1 >= y2 ) {
  264.         m = y1; y1 = y2; y2 = m;
  265.         m = x1; x1 = x2; x2 = m;
  266.         m = c1; c1 = c2; c2 = m; };
  267.  
  268.     x12 = x1 << 16;
  269.     x13 = x1 << 16;
  270.     x23 = x2 << 16;
  271.     
  272.     c12 = c1 << 16;
  273.     c13 = c1 << 16;
  274.     c23 = c2 << 16;
  275.  
  276.     if ( y2 != y1 ) {
  277.         m12 = ((x2-x1) << 16) / (y2-y1);
  278.         mc12 = ((c2-c1) << 16) / (y2-y1);
  279.     };
  280.     if ( y3 != y1 ) {
  281.         m13 = ((x3-x1) << 16) / (y3-y1);
  282.         mc13 = ((c3-c1) << 16) / (y3-y1);
  283.     };
  284.     if ( y3 != y2 ) {
  285.         m23 = ((x3-x2) << 16) / (y3-y2); 
  286.         mc23 = ((c3-c2) << 16) / (y3-y2);
  287.     };
  288.  
  289.     dcdx12 = (x3-x1)*(y2-y1)-(x2-x1)*(y3-y1);
  290.     if ( dcdx12 != 0 )
  291.          dcdx12 = double((c3-c1)*(y2-y1)-(c2-c1)*(y3-y1)) / dcdx12 * 65536;
  292.  
  293.     dcdx23 = (x3-x1)*(y3-y2)-(x3-x2)*(y3-y1);
  294.     if ( dcdx23 != 0 )
  295.          dcdx23 = double((c3-c1)*(y3-y2)-(c3-c2)*(y3-y1)) / dcdx23 * 65536;
  296.  
  297.     for ( i = y1; i < y2; i++ ) {
  298.         VESA_HLineG8BFast( x12 >> 16, x13 >> 16, i, c12, c13, dcdx12, S );
  299.         x12 += m12;
  300.         x13 += m13;
  301.         c12 += mc12;
  302.         c13 += mc13;
  303.     };
  304.  
  305.     for ( ; i <= y3; i++ ) {
  306.         VESA_HLineG8BFast( x23 >> 16, x13 >> 16, i, c23, c13, dcdx23, S );
  307.         x23 += m23;
  308.         x13 += m13;
  309.         c23 += mc23;
  310.         c13 += mc13;
  311.     };
  312. };
  313.  
  314. void VESA_FilledTriangleTex8BCF( long x1, long y1, long x2, long y2, long x3, long y3,
  315.                                  long tx1, long ty1, long tx2, long ty2,
  316.                                  long tx3, long ty3, DWORD MUL, WORD S ) {
  317.     long m,i;
  318.     long x12,x13,x23,m12,m13,m23;
  319.     long tx12,tx13,tx23,mtx12,mtx13,mtx23;
  320.     long ty12,ty13,ty23,mty12,mty13,mty23;
  321.     long dtxdx12,dtxdx23,dtydx12,dtydx23;
  322.     
  323.     if ( y1 >= y2 ) {
  324.         m = y1; y1 = y2; y2 = m;
  325.         m = x1; x1 = x2; x2 = m;
  326.         m = tx1; tx1 = tx2; tx2 = m; 
  327.         m = ty1; ty1 = ty2; ty2 = m; };
  328.     if ( y2 >= y3 ) {
  329.         m = y2; y2 = y3; y3 = m;
  330.         m = x2; x2 = x3; x3 = m;
  331.         m = tx2; tx2 = tx3; tx3 = m; 
  332.         m = ty2; ty2 = ty3; ty3 = m; };
  333.     if ( y1 >= y2 ) {
  334.         m = y1; y1 = y2; y2 = m;
  335.         m = x1; x1 = x2; x2 = m;
  336.         m = tx1; tx1 = tx2; tx2 = m; 
  337.         m = ty1; ty1 = ty2; ty2 = m; };
  338.         
  339.     x12 = x1 << 16;
  340.     x13 = x1 << 16;
  341.     x23 = x2 << 16;
  342.     
  343.     tx12 = tx1 << 16;
  344.     tx13 = tx1 << 16;
  345.     tx23 = tx2 << 16;
  346.     
  347.     ty12 = ty1 << 16;
  348.     ty13 = ty1 << 16;
  349.     ty23 = ty2 << 16;
  350.     
  351.     if ( y2 != y1 ) { m12 = double(x2-x1) / (y2-y1) * 65536;
  352.                       mtx12 = double(tx2-tx1) / (y2-y1) * 65536; 
  353.                       mty12 = double(ty2-ty1) / (y2-y1) * 65536; };
  354.     if ( y3 != y1 ) { m13  = double(x3-x1) / (y3-y1) * 65536; 
  355.                       mtx13 = double(tx3-tx1) / (y3-y1) * 65536; 
  356.                       mty13 = double(ty3-ty1) / (y3-y1) * 65536; };
  357.     if ( y3 != y2 ) { m23 = double(x3-x2)/ (y3-y2) * 65536; 
  358.                       mtx23 = double(tx3-tx2) / (y3-y2) * 65536; 
  359.                       mty23 = double(ty3-ty2) / (y3-y2) * 65536; };
  360.  
  361.     dtxdx12 = (x3-x1)*(y2-y1)-(x2-x1)*(y3-y1);
  362.     if ( dtxdx12 != 0 )
  363.          dtxdx12 = double((tx3-tx1)*(y2-y1)-(tx2-tx1)*(y3-y1)) / dtxdx12 * 65536;
  364.  
  365.     dtxdx23 = (x3-x1)*(y3-y2)-(x3-x2)*(y3-y1);
  366.     if ( dtxdx23 != 0 )
  367.          dtxdx23 = double((tx3-tx1)*(y3-y2)-(tx3-tx2)*(y3-y1)) / dtxdx23 * 65536;
  368.  
  369.     dtydx12 = (x3-x1)*(y2-y1)-(x2-x1)*(y3-y1);
  370.     if ( dtydx12 != 0 )
  371.          dtydx12 = double((ty3-ty1)*(y2-y1)-(ty2-ty1)*(y3-y1)) / dtydx12 * 65536;
  372.  
  373.     dtydx23 = (x3-x1)*(y3-y2)-(x3-x2)*(y3-y1);
  374.     if ( dtydx23 != 0 )
  375.          dtydx23 = double((ty3-ty1)*(y3-y2)-(ty3-ty2)*(y3-y1)) / dtydx23 * 65536;
  376.  
  377.     for ( i = y1; i < y2; i++ ) {
  378.         VESA_HLineTex8BFast( x12 >> 16, x13 >> 16, i, tx12, ty12, tx13, ty13, dtxdx12,
  379.                              dtydx12, MUL, S );
  380.         x12 += m12;
  381.         x13 += m13;
  382.         tx12 += mtx12;
  383.         ty12 += mty12;
  384.         tx13 += mtx13;
  385.         ty13 += mty13; };
  386.  
  387.     for ( ; i <= y3; i++ ) {
  388.         VESA_HLineTex8BFast( x13 >> 16, x23 >> 16, i, tx13, ty13, tx23, ty23, dtxdx23,
  389.                              dtydx23, MUL, S );
  390.         x13 += m13;
  391.         x23 += m23;
  392.         tx13 += mtx13;
  393.         ty13 += mty13;
  394.         tx23 += mtx23;
  395.         ty23 += mty23; };
  396. };
  397.  
  398.  
  399.